package com.tensquare.friend.controller;

import com.tensquare.friend.client.UserClient;
import com.tensquare.friend.service.FriendService;
import entity.Result;
import entity.StatusCode;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin
@RequestMapping("/friend")
public class FriendController {

    @Autowired
    private FriendService friendService;

    @Autowired
    private HttpServletRequest request;


    /**
     * 推荐好友操作
     * @param friendId 对方id
     * @param type 类型: 喜欢1 不喜欢2
     * @return
     */
    @RequestMapping(value = "/like/{friendId}/{type}", method = RequestMethod.PUT)
    public Result ifLike(@PathVariable("friendId") String friendId, @PathVariable("type") String type) {
        // 从request域中获取令牌相关信息
        Claims claims = (Claims) request.getAttribute("claims_user");
        Result result = friendService.ifLike(claims, friendId, type);
        return result;
    }

    /**
     * 删除好友
     */
    @RequestMapping(value = "/{friendId}", method = RequestMethod.DELETE)
    public Result deleteFriend(@PathVariable("friendId") String friendId) {
        // 从request域中获取令牌相关信息
        Claims claims = (Claims) request.getAttribute("claims_user");
        Result result = friendService.deleteFriend(claims, friendId);
        return result;
    }

}

